import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
public class NGuessNumber {
    private static int[] ints=new int[3];
    public int suij(){
        Random r=new Random();
        return r.nextInt(10);
    }
    public static void main(String[] args) {
        int sha=0;
        int bi=0;
        NGuessNumber t3=new NGuessNumber();
        String four="";
        Set<Integer> set = new HashSet<Integer>();
        while(four.length()<4){
            int da=t3.suij();
            if(!set.contains(da)){
                set.add(da);
                four+=da;
            }
        }
        int a=Integer.parseInt(four)/1000;
        int b=Integer.parseInt(four)/100%10;
        int c=Integer.parseInt(four)/10%10;
        int d=Integer.parseInt(four)%10;
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输入四位数:");
            String inputString = scanner.next();
            int x=Integer.parseInt(inputString)/1000;
            int y=Integer.parseInt(inputString)/100%10;
            int z=Integer.parseInt(inputString)/10%10;
            int w=Integer.parseInt(inputString)%10;
            if (!inputString.equals(four)) {
                System.out.println("不对");
            } else if (a==x&&b==y&&c==z&&d==w){
                System.out.println("对了,还要重玩一局吗？y/n");
                String pd = scanner.next();
                if("y".equals(pd)){
                    for(int i = 0; i<4 ;i++){
                        set.remove(i);
                    }
                    four="";
                    while(four.length()<4){
                        int da=t3.suij();
                        if(!set.contains(da)){
                            set.add(da);
                            four+=da;
                        }
                    }
                    System.out.println(four);
                }else if ("n".equals(pd)){
                    break;
                }
            }
        }
    }
}
